package com.goldgov.notifyrecord.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.login.web.model.LoginAuthUser;
import com.goldgov.notice.service.NoticeService;
import com.goldgov.notifyrecord.service.NotifyRecord;
import com.goldgov.notifyrecord.service.NotifyRecordService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/** 
 * @ClassName: NotifyRecordController 
 * @Description: TODO
 * @author hanxiangyu
 * @date 2018年6月29日 下午6:14:37 
 */
@RestController
@RequestMapping("/workbench/notifyrecord")
@Api("远程教育服务接口")
public class NotifyRecordController {
	
	@Autowired
	private NotifyRecordService notifyRecordService;
	
	@Autowired
	private NoticeService noticeService;
	
	@PostMapping
	@ApiOperation(value = "新增", notes = "新增" )
	public void addNotifyRecod() {
		NotifyRecord nr = new NotifyRecord();
		String[] userIds = new String[]{"admin"};
		nr.setNotifySenderCode("notify");	//发送机编码
		nr.setModelId("f61b1ecb-48f9-11e8-9704-0242ac130008");//通知模型ID 三会一课
		nr.setModelDesc("测试");//标题
		nr.setSenderId("admin");//发送人ID
		nr.setSenderName("admin");//发送人名称
		nr.setContent("今日通知内容： 计划任务");
		nr.setSendTime(new Date());
		nr.setState(1);
		nr.setUserIds(userIds);
		nr.setReceiverState(2);//未读
		nr.setTemplateId("65b54024-74fb-11e8-953b-0242ac130004");
		nr.setVisible(1);
		nr.setReceipt("2");
		notifyRecordService.addNotifyRecord(nr);
	}
	
	@PostMapping("/studyWarning")
	@ApiOperation(value = "学习预警", notes = "学习预警" )
	public void studyWarning(NotifyRecord obj,HttpServletRequest request,Model model,HttpServletResponse response) {
		LoginAuthUser user=LoginAuthUser.getUser(request);
		obj.setSenderId(user.getEntityID());
		obj.setSenderName(user.getUserName());
		noticeService.addStudyWarning(obj);
		
	}
	
	
}
